package bigoo.common.communication;

import java.util.HashMap;
import java.util.Map;


public class MessageBuilderFactory {
    
    private static MessageBuilderFactory builderHandler = new MessageBuilderFactory();
    
    public static MessageBuilderFactory getInstance() {
	return builderHandler;
    }
    
    private Map<String, MessageBuilder> builders = new HashMap<String, MessageBuilder>();
    
    private MessageBuilderFactory() {
	
    }
    
    public void registerBuilder(String messageIdentifier, MessageBuilder builder) {
	this.builders.put(messageIdentifier, builder);
    }
    
    public MessageBuilder getBuilder(String messageIdentifier) throws UnknownMessageException {
	if (this.builders.containsKey(messageIdentifier)) {
	    return this.builders.get(messageIdentifier);
	} else {
	    throw new UnknownMessageException(messageIdentifier);
	}
    }

}
